home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / source / src / graph / _g_array.c next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  3.0 KB  |  133 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  _g_array.c
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #include <LEDA/graph.h>
  16. #include <LEDA/node_matrix.h>
  17.  
  18.  
  19. //------------------------------------------------------------------------------
  20. // node and edge arrays       
  21. //------------------------------------------------------------------------------
  22.  
  23. void graph_array<node>::init(const graph& G, int n, GenPtr i)
  24. { if (g!=0) clear();
  25.   g = (graph*)&G;
  26.   mx_i=n-1;
  27.   arr=new GenPtr[n];
  28.   if (arr==0)  error_handler(1,"node_array: out of memory");
  29.   for (int j=0; j<n; j++) { copy_entry(i); arr[j] = i; }
  30. }
  31.  
  32. void graph_array<node>::init(const graph_array<node>& A)
  33. { if (g!=0) clear();
  34.   g = A.g;
  35.   mx_i=A.mx_i;
  36.   arr=new GenPtr[mx_i+1];
  37.   if (arr==0)  error_handler(1,"node_array: out of memory");
  38.   for (int j=0;j<=mx_i;j++)
  39.   { GenPtr x = A.arr[j];
  40.     copy_entry(x);
  41.     arr[j] = x;
  42.    }
  43.  }
  44.  
  45. void graph_array<node>::clear()
  46. { int j;
  47.   for (j=0;j<=mx_i;j++) clear_entry(arr[j]);
  48.   if (arr) delete[] arr;
  49.   arr=0; g=0; mx_i = -1;
  50.  }
  51.  
  52.  
  53.  
  54. void graph_array<edge>::init(const graph& G, int n, GenPtr i)
  55. { if (g!=0) clear();
  56.   g = (graph*)&G;
  57.   mx_i=n-1;
  58.   arr=new GenPtr[n];
  59.   if (arr==0)  error_handler(1,"edge_array: out of memory");
  60.   for (int j=0; j<n; j++) { copy_entry(i); arr[j] = i; }
  61. }
  62.  
  63. void graph_array<edge>::init(const graph_array<edge>& A)
  64. { if (g!=0) clear();
  65.   g = A.g;
  66.   mx_i=A.mx_i;
  67.   arr=new GenPtr[mx_i+1];
  68.   if (arr==0)  error_handler(1,"edge_array: out of memory");
  69.   for (int j=0;j<=mx_i;j++)
  70.   { GenPtr x = A.arr[j];
  71.     copy_entry(x);
  72.     arr[j] = x;
  73.    }
  74.  }
  75.  
  76. void graph_array<edge>::clear()
  77. { int j;
  78.   for (j=0;j<=mx_i;j++) clear_entry(arr[j]);
  79.   if (arr) delete[] arr;
  80.   arr=0; g=0; mx_i = -1;
  81.  }
  82.  
  83.  
  84.  
  85.  
  86. //------------------------------------------------------------------------------
  87. // node matrices
  88. //------------------------------------------------------------------------------
  89.  
  90.  
  91. void Node_Matrix::init(const graph& G, int n, GenPtr x) 
  92. { int i,j;
  93.   g = (graph*)&G;
  94.   M.init(G,n,0);
  95.   for(i=0;i<M.size();i++) 
  96.     { M.elem(i) = new graph_array<node>;
  97.       M.elem(i) -> init(G,n,0);
  98.       for(j=0;j<M.elem(i)->size();j++) 
  99.         { copy_entry(x);
  100.           M.elem(i)->entry(j) = x;
  101.          }
  102.      }
  103. }
  104.  
  105. void Node_Matrix::init(const Node_Matrix& A) 
  106. { int i,j;
  107.   g = A.g;
  108.   M.init(*g,0);
  109.   for(i=0;i<M.size();i++) 
  110.     { M.elem(i) = new graph_array<node>;
  111.       M.elem(i) -> init(*g,g->max_i(node(0)),0);
  112.       for(j=0;j<M.elem(i)->size();j++) 
  113.         { GenPtr x = A.M.elem(i)->entry(j);
  114.           copy_entry(x);
  115.           M.elem(i)->entry(j) = x;
  116.          }
  117.      }
  118. }
  119.  
  120. void Node_Matrix::clear()
  121. { int i,j;
  122.   for(i=0;i<M.size();i++) 
  123.    { for(j=0;j<M.elem(i)->size();j++) 
  124.       { GenPtr x = M.elem(i)->entry(j);
  125.         clear_entry(x); 
  126.        }
  127.      delete M.elem(i);
  128.     }
  129.   M.clear();
  130. }
  131.  
  132.